﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenSoftStore.BusinessLogic.Common;
using OpenSoftStore.Client.Common;
using OpenSoftStore.Orm.Model;

namespace OpenSoftStore.Client.UIL.ManageProduct
{
    public partial class StoreSetWindow : Form
    {
        private const string _ShopId = "b0def1a7-bf25-45f2-b65a-6dc586dbfc2c";
        private ComboLogic comboBll;
        private List<T_Combo> comboList;
        public StoreSetWindow()
        {
            comboBll = new ComboLogic();
            comboList = new List<T_Combo>();


            InitializeComponent();

            dgvStore.AutoGenerateColumns = false;
            comboList = comboBll.GetComboByBuzType("Pos", _ShopId).ToList();

            dgvStore.DataSource = comboList;
            SPACommon.SetDataGridStyle(dgvStore);
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            dgvStore.EndEdit(DataGridViewDataErrorContexts.Commit);
            var list = (List<T_Combo>)dgvStore.DataSource;
            int count = list.Where(c => c.Value2 == "是").Count();
            if (count != 1)
            {
                FormSysMessage.ShowSuccessMsg("只能选择一条优先仓库！");
                return;
            }
            if (comboBll.UpdateCombo(comboList) > 0)
                FormSysMessage.ShowSuccessMsg("设置成功！");
            this.Close();
            ProductList.Instance.GenerateColumnText(comboBll.GetComboByBuzType("Pos", _ShopId));
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
